package com.project.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.project.bean.SellBean;
import com.project.bean.SellCarBean;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.ResultType;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ISellCarMapper extends BaseMapper<SellCarBean> {

    @Select("SELECT SUM(p.`p_sellPrice`*s.`sc_num`) FROM t_product p ,t_sellCar s " +
            "WHERE p.`pk_product`=s.`fk_productId` AND s.`fk_userId`=#{userId};")
    @ResultType(Integer.class)
    Integer getTotalPrice(Integer userId);

    @Select("SELECT s.*,p.* FROM t_sellCar s,t_product p " +
            "WHERE s.`fk_productId`=p.`pk_product` AND s.`fk_userId`=#{userId};")
    @ResultMap("sellCarMap")
    List<SellCarBean> findByUserId(Integer userId);

}
